﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Script.Serialization;
using WebServer.DBAccess;

namespace WebServer.Biz
{
    public class SendCodeBiz
    {
        /// <summary>
        /// 记录可用验证
        /// </summary>
        /// <param name="Email"></param>
        /// <param name="Mobile"></param>
        /// <param name="Code"></param>
        /// <param name="EndTime"></param>
        /// <param name="Usable"></param>
        /// <returns></returns>
        public string Insert(string Email, string Mobile, string Code, DateTime EndTime, bool Usable)
        {
            string request = string.Empty; 
            Email = string.IsNullOrEmpty(Email) ? Email : (Email == "" ? Email : Email.ToLower());
            Mobile = string.IsNullOrEmpty(Mobile) ? Mobile : (Mobile == "" ? Mobile : Mobile.ToLower());
            request = new SendCodeDA().Insert(Email, Mobile, Code, EndTime, Usable);
            return request;
        }
        /// <summary>
        /// 序列化字符串
        /// </summary>
        /// <param name="jsonData"></param>
        /// <returns></returns>
        public Dictionary<string, object> JsonToDictionary(string jsonData)
        {
            Dictionary<string, object> request = new Dictionary<string, object>();
            //实例化JavaScriptSerializer类的新实例
            JavaScriptSerializer jss = new JavaScriptSerializer();
            try
            {
                request = jss.Deserialize<Dictionary<string, object>>(jsonData);
            }
            catch (Exception ex)
            {
            }
            return request;
        }
        /// <summary>
        /// 生成验证码
        /// </summary>
        /// <param name="length">指定验证码的长度</param>
        /// <returns></returns>
        public string ValidateCode(int length)
        {
            int[] randMembers = new int[length];
            int[] validateNums = new int[length];
            string validateNumberStr = "";
            //生成起始序列值
            int seekSeek = unchecked((int)DateTime.Now.Ticks);
            Random seekRand = new Random(seekSeek);
            int beginSeek = (int)seekRand.Next(0, Int32.MaxValue - length * 10000);
            int[] seeks = new int[length];
            for (int i = 0; i < length; i++)
            {
                beginSeek += 10000;
                seeks[i] = beginSeek;
            }
            //生成随机数字
            for (int i = 0; i < length; i++)
            {
                Random rand = new Random(seeks[i]);
                int pownum = 1 * (int)Math.Pow(10, length);
                randMembers[i] = rand.Next(pownum, Int32.MaxValue);
            }
            //抽取随机数字
            for (int i = 0; i < length; i++)
            {
                string numStr = randMembers[i].ToString();
                int numLength = numStr.Length;
                Random rand = new Random();
                int numPosition = rand.Next(0, numLength - 1);
                validateNums[i] = Int32.Parse(numStr.Substring(numPosition, 1));
            }
            //生成验证码
            for (int i = 0; i < length; i++)
            {
                validateNumberStr += validateNums[i].ToString();
            }
            return validateNumberStr;
        }

        /// <summary>
        /// 查询可用性
        /// </summary>
        /// <param name="Mobile"></param>
        /// <returns></returns>
        public string HasCode(string Mobile)
        {
            string request = "";
            Mobile = string.IsNullOrEmpty(Mobile) ? Mobile : (Mobile == "" ? Mobile : Mobile.ToLower());
            request = new SendCodeDA().HasCode(Mobile);
            return request;
        }



        /// <summary>
        /// 认证
        /// </summary>
        /// <param name="Email"></param>
        /// <param name="Mobile"></param>
        /// <param name="Code"></param>
        /// <returns></returns>
        public bool LoginCode(string Email, string Mobile, string Code)
        {
            bool request = false;
            Email = string.IsNullOrEmpty(Email) ? Email : (Email == "" ? Email : Email.ToLower());
            Mobile = string.IsNullOrEmpty(Mobile) ? Mobile : (Mobile == "" ? Mobile : Mobile.ToLower());
            request = new SendCodeDA().LoginCode(Email, Mobile, Code);
            return request;
        }

        /// <summary>
        /// 认证
        /// </summary>
        /// <param name="Email"></param>
        /// <param name="Mobile"></param>
        /// <param name="Code"></param>
        /// <returns></returns>
        public bool SecurityLogin(string Email, string Mobile, string Code)
        {
            bool request = false;
            Email = string.IsNullOrEmpty(Email) ? Email : (Email == "" ? Email : Email.ToLower());
            Mobile = string.IsNullOrEmpty(Mobile) ? Mobile : (Mobile == "" ? Mobile : Mobile.ToLower());
            request = new SendCodeDA().SecurityLogin(Email, Mobile, Code);
            return request;
        }


        /// <summary>
        /// 注册模板
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public string RegHtml(string url)
        {
            string html = "<table align='center' border='0' cellpadding='0' cellspacing='0' style='border-collapse: collapse; width: 100%; max-width: 600px;' class='content'>" +
                            "<tr><td style='padding: 15px 10px 15px 10px;'>" +
                                    "<table border='0' cellpadding='0' cellspacing='0' width='100%'><tr>" +
                                            "<td align='center' style='color: #aaaaaa; font-family: Arial, sans-serif; font-size: 12px;'>" +
                                                "邮箱未能正常显示?  <a href='www.17ybk.com' style='color: #4ca5a9;'>查看官网</a>" +
                                            "</td>" +
                                    "</tr></table>" +
                            "</td></tr>" +
                            "<tr>" +
                                "<td align='center' bgcolor='#4ca5a9' style='padding: 20px 20px 20px 20px; color: #ffffff; font-family: Arial, sans-serif; font-size: 36px; font-weight: bold;'>" +
                                    "欢迎加入17YBK!" +
                                "</td>" +
                            "</tr>" +
                            "<tr>" +
                                "<td align='center' bgcolor='#ffffff' style='padding: 40px 20px 40px 20px; color: #555555; font-family: Arial, sans-serif; font-size: 20px; line-height: 30px; border-bottom: 1px solid #f6f6f6;'>" +
                                    "<b>注册账号邮箱验证，请点击如下按钮：</b>" +
                                "</td>" +
                            "</tr>" +

                            "<tr>" +
                                "<td align='center' bgcolor='#f9f9f9' style='padding: 30px 20px 30px 20px; font-family: Arial, sans-serif; border-bottom: 1px solid #f6f6f6;'>" +
                                    "<table bgcolor='#4ca5a9' border='0' cellspacing='0' cellpadding='0' class='buttonwrapper'>" +
                                        "<tr>" +
                                            "<td align='center' height='50' style=' padding: 0 25px 0 25px; font-family: Arial, sans-serif; font-size: 16px; font-weight: bold;' class='button'>" +
                                                "<a href='" + url + "' style='color: #ffffff; text-align: center; text-decoration: none;'>立刻验证</a>" +
                                            "</td>" +
                                        "</tr>" +
                                    "</table>" +
                                "</td>" +
                            "</tr>" +
                            "<tr>" +
                                "<td align='center' bgcolor='#f9f9f9' style='padding: 20px 20px 0 20px; color: #555555; font-family: Arial, sans-serif; font-size: 20px; line-height: 30px;'>" +
                                    "如果无法点击按钮验证，请复制以下地址至浏览器中访问！" +
                                "</td>" +
                            "</tr>" +
                            "<tr>" +
                                "<td align='center' bgcolor='#f9f9f9' style='padding: 20px 20px 0 20px; color: #555555; font-family: Arial, sans-serif; font-size: 20px; line-height: 30px;'>" +
                                    url +
                                "</td>" +
                            "</tr>" +
                            "<tr>" +
                                "<td align='center' bgcolor='#dddddd' style='padding: 15px 10px 15px 10px; color: #555555; font-family: Arial, sans-serif; font-size: 12px; line-height: 18px;'>" +
                                    "<b>Company Inc.</b><br/>SHANGLAN - 17YBK" +
                                "</td>" +
                            "</tr>" +
                            "<tr>" +
                                "<td style='padding: 15px 10px 15px 10px;'>" +
                                    "<table border='0' cellpadding='0' cellspacing='0' width='100%'>" +
                                        "<tr>" +
                                            "<td align='center' width='100%' style='color: #999999; font-family: Arial, sans-serif; font-size: 12px;'>" +
                                                DateTime.Now.ToString("yyyy-MM-dd") + " &copy; <a href='http://www.17ybk.com' style='color: #4ca5a9;'>17YBK.COM</a>" +
                                            "</td>" +
                                        "</tr>" +
                                    "</table>" +
                                "</td>" +
                            "</tr>" +
                        "</table>";
            return html;
        }




        /// <summary>
        /// 找回密码模板
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public string PassHtml(string Code)
        {
            string html = "<table align='center' border='0' cellpadding='0' cellspacing='0' style='border-collapse: collapse; width: 100%; max-width: 600px;' class='content'>" +
                            "<tr><td style='padding: 15px 10px 15px 10px;'>" +
                                    "<table border='0' cellpadding='0' cellspacing='0' width='100%'><tr>" +
                                            "<td align='center' style='color: #aaaaaa; font-family: Arial, sans-serif; font-size: 12px;'>" +
                                                "邮箱未能正常显示?  <a href='www.17ybk.com' style='color: #4ca5a9;'>查看官网</a>" +
                                            "</td>" +
                                    "</tr></table>" +
                            "</td></tr>" +
                            "<tr>" +
                                "<td align='center' bgcolor='#4ca5a9' style='padding: 20px 20px 20px 20px; color: #ffffff; font-family: Arial, sans-serif; font-size: 36px; font-weight: bold;'>" +
                                    "17YBK密码重置" +
                                "</td>" +
                            "</tr>" +
                            "<tr>" +
                                "<td align='center' bgcolor='#ffffff' style='padding: 40px 20px 40px 20px; color: #555555; font-family: Arial, sans-serif; font-size: 20px; line-height: 30px; border-bottom: 1px solid #f6f6f6;'>" +
                                    "<b>找回密码请复制如下验证码：</b>" +
                                "</td>" +
                            "</tr>" +

                            "<tr>" +
                                "<td align='center' bgcolor='#f9f9f9' style='padding: 30px 20px 30px 20px; font-family: Arial, sans-serif; border-bottom: 1px solid #f6f6f6;'>" +
                                    "<table bgcolor='#4ca5a9' border='0' cellspacing='0' cellpadding='0' class='buttonwrapper'>" +
                                        "<tr>" +
                                            "<td align='center' height='50' style=' padding: 0 25px 0 25px; font-family: Arial, sans-serif; font-size: 22px; font-weight: bold;'>" +
                                                Code +
                                            "</td>" +
                                        "</tr>" +
                                    "</table>" +
                                "</td>" +
                            "</tr>" +

                            "<tr>" +
                                "<td style='padding: 15px 10px 15px 10px;'>" +
                                    "<table border='0' cellpadding='0' cellspacing='0' width='100%'>" +
                                        "<tr>" +
                                            "<td align='center' width='100%' style='color: #999999; font-family: Arial, sans-serif; font-size: 12px;'>" +
                                                DateTime.Now.ToString("yyyy-MM-dd") + " &copy; <a href='http://www.17ybk.com' style='color: #4ca5a9;'>17YBK.COM</a>" +
                                            "</td>" +
                                        "</tr>" +
                                    "</table>" +
                                "</td>" +
                            "</tr>" +
                        "</table>";
            return html;
        }

        /// <summary>
        /// 绑定验证码
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public string BoundHtml(string Code)
        {
            string html = "<table align='center' border='0' cellpadding='0' cellspacing='0' style='border-collapse: collapse; width: 100%; max-width: 600px;' class='content'>" +
                            "<tr><td style='padding: 15px 10px 15px 10px;'>" +
                                    "<table border='0' cellpadding='0' cellspacing='0' width='100%'><tr>" +
                                            "<td align='center' style='color: #aaaaaa; font-family: Arial, sans-serif; font-size: 12px;'>" +
                                                "邮箱未能正常显示?  <a href='www.17ybk.com' style='color: #4ca5a9;'>查看官网</a>" +
                                            "</td>" +
                                    "</tr></table>" +
                            "</td></tr>" +
                            "<tr>" +
                                "<td align='center' bgcolor='#4ca5a9' style='padding: 20px 20px 20px 20px; color: #ffffff; font-family: Arial, sans-serif; font-size: 36px; font-weight: bold;'>" +
                                    "绑定邮箱 - 一起邮币卡一路伴随您" +
                                "</td>" +
                            "</tr>" +
                            "<tr>" +
                                "<td align='center' bgcolor='#ffffff' style='padding: 40px 20px 40px 20px; color: #555555; font-family: Arial, sans-serif; font-size: 20px; line-height: 30px; border-bottom: 1px solid #f6f6f6;'>" +
                                    "<b>绑定邮箱请复制如下验证码：</b>" +
                                "</td>" +
                            "</tr>" +

                            "<tr>" +
                                "<td align='center' bgcolor='#f9f9f9' style='padding: 30px 20px 30px 20px; font-family: Arial, sans-serif; border-bottom: 1px solid #f6f6f6;'>" +
                                    "<table bgcolor='#4ca5a9' border='0' cellspacing='0' cellpadding='0' class='buttonwrapper'>" +
                                        "<tr>" +
                                            "<td align='center' height='50' style=' padding: 0 25px 0 25px; font-family: Arial, sans-serif; font-size: 22px; font-weight: bold;'>" +
                                                Code +
                                            "</td>" +
                                        "</tr>" +
                                    "</table>" +
                                "</td>" +
                            "</tr>" +

                            "<tr>" +
                                "<td style='padding: 15px 10px 15px 10px;'>" +
                                    "<table border='0' cellpadding='0' cellspacing='0' width='100%'>" +
                                        "<tr>" +
                                            "<td align='center' width='100%' style='color: #999999; font-family: Arial, sans-serif; font-size: 12px;'>" +
                                                DateTime.Now.ToString("yyyy-MM-dd") + " &copy; <a href='http://www.17ybk.com' style='color: #4ca5a9;'>17YBK.COM</a>" +
                                            "</td>" +
                                        "</tr>" +
                                    "</table>" +
                                "</td>" +
                            "</tr>" +
                        "</table>";
            return html;
        }
        /// <summary>
        /// 申请成为分析师、经纪商
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        public string CheckHtml(string returnUrl,int Type)
        {
            string remark = "";
            if (Type == 2)
            { remark = "<b>审核通过，恭喜您成为" + returnUrl + "</b>"; }
            else if (Type == 3)
            { remark = "<b>您申请成为" + returnUrl + "审核未通过。详情请查看私信</b>"; }
            string html = "<table align='center' border='0' cellpadding='0' cellspacing='0' style='border-collapse: collapse; width: 100%; max-width: 600px;' class='content'>" +
                            "<tr><td style='padding: 15px 10px 15px 10px;'>" +
                                    "<table border='0' cellpadding='0' cellspacing='0' width='100%'><tr>" +
                                            "<td align='center' style='color: #aaaaaa; font-family: Arial, sans-serif; font-size: 12px;'>" +
                                                "邮箱未能正常显示?  <a href='www.17ybk.com' style='color: #4ca5a9;'>查看官网</a>" +
                                            "</td>" +
                                    "</tr></table>" +
                            "</td></tr>" +
                            "<tr>" +
                                "<td align='center' bgcolor='#4ca5a9' style='padding: 20px 20px 20px 20px; color: #ffffff; font-family: Arial, sans-serif; font-size: 36px; font-weight: bold;'>" +
                                    "欢迎加入17YBK!" +
                                "</td>" +
                            "</tr>" +
                            "<tr>" +
                                "<td align='center' bgcolor='#ffffff' style='padding: 40px 20px 40px 20px; color: #555555; font-family: Arial, sans-serif; font-size: 20px; line-height: 30px; border-bottom: 1px solid #f6f6f6;'>" +
                                    remark +
                                "</td>" +
                            "</tr>" +
                            "<tr>" +
                                "<td align='center' bgcolor='#dddddd' style='padding: 15px 10px 15px 10px; color: #555555; font-family: Arial, sans-serif; font-size: 12px; line-height: 18px;'>" +
                                    "<b>Company Inc.</b><br/>SHANGLAN - 17YBK" +
                                "</td>" +
                            "</tr>" +
                            "<tr>" +
                                "<td style='padding: 15px 10px 15px 10px;'>" +
                                    "<table border='0' cellpadding='0' cellspacing='0' width='100%'>" +
                                        "<tr>" +
                                            "<td align='center' width='100%' style='color: #999999; font-family: Arial, sans-serif; font-size: 12px;'>" +
                                                DateTime.Now.ToString("yyyy-MM-dd") + " &copy; <a href='http://www.17ybk.com' style='color: #4ca5a9;'>17YBK.COM</a>" +
                                            "</td>" +
                                        "</tr>" +
                                    "</table>" +
                                "</td>" +
                            "</tr>" +
                        "</table>";
            return html;
        }

        public string TestCheckHtml(string Code)
        {
            string html = "<!doctype html>" +
"<html>" +
"<head>" +
"<meta charset='utf-8'>" +
"<title>一起邮币卡</title>" +
"</head>" +
"<body>" +
"<div style='width:600px; height:60px; background:url(http://www.17ybk.com/edm/20160513/images/top.jpg) #580000'></div>" +
"<div style='width:600px; height:709px; background:url(http://www.17ybk.com/edm/20160513/images/bg_m.jpg) #580000 top; margin:0;'>" +
"<p style='font-size:26px; color:#fff; padding-top:250px; line-height:60px;margin:0; text-align:center;'>尊敬的 <span style='color:#ffff00;'>" + Code + "</span>号经纪会员 您好</p>" +
"<p style='font-size:24px; line-height:60px;margin:0;text-align:center; color:#fff;'>一起邮币卡 平台全新上线！诚邀您的入驻！</p>" +
"<p style='padding:0 30px; line-height:24px;margin:0; text-align:center; color:#fffbcd;'><span style='color:#ffff00;'>一起邮币卡</span>于2016年3月正式上线" +
 "   ，已入驻200余家经纪商，10余名行业金牌分析师，平台用户达20000+，并与多家交易所达成战略合作。旗下目前有邮币卡行业综合性门户网站" +
  "      (<a href='http://www.17ybk.com' target='_blank' style='color:#ffff00;'>WWW.17YBK.COM</a>)与资讯行情APP" +
   "         (<a href='http://wap.17ybk.com/home/down' target='_blank' style='color:#ffff00;'>一起邮币卡</a>)。我们致力于成为行业内第一家跨平台一站式自营销门户服务商。诚邀您见证" +
    "            一起邮币卡的发展之路！期待您加入我们！携手共进！</p><br>" +
"<p style='text-align:center; margin:0;'><a href='http://www.17ybk.com/User/Reg' target='_blank' style='display:inline-block; background:#fff799; width:283px;height:61px; line-height:61px; text-decoration:none; font-size:30px; font-family: 'Microsoft YaHei'; '>" +
        "<strong style='color:#7d0000;'>点击免费入驻</strong></a></p><br>" +
"<p style='text-align:center; margin:0;'><a href='http://q.eqxiu.com/s/Gbzx6Br3' target='_blank' style='display:inline-block; background:#000; width:283px;height:61px; line-height:61px;	text-decoration:none; font-size:25px; font-family: 'Microsoft YaHei'; '><strong style=' color:#fff799'>" +
            "查看邀请函</strong></a></p></div>" +
"<div style='width:600px; height:361px; background:url(http://www.17ybk.com/edm/20160513/images/bg_m2.jpg) #580000; text-align:center;'><br>" +
"<div style='width:210px; float:left; margin-left:100px; line-height:20px;'>" +
"<p style='font-size:28px; color:#fff; '>APP下载</p>" +
"<a href='http://wap.17ybk.com/home/down' target='_blank'><img src='http://www.17ybk.com/edm/20160513/images/img_1.jpg' alt='APP下载二维码' title='APP下载二维码' width='195' height='193' /></a></div>" +
"<div style='width:210px; float:left; line-height:20px;'>" +
"<p style='font-size:28px; color:#fff;'>关注微信号</p><img src='http://www.17ybk.com/edm/20160513/images/img_2.jpg' width='195' height='193' alt='微信二维码' title='微信二维码'/></div>" +
"<p style='clear:both; font-size:18px; line-height:40px; color:#fff; text-align:center;'>官方网站：<a href='http://www.17ybk.com' target='_blank' style='color:#ffff00;'>http://www.17ybk.com</a></p>" +
"</div>" +
"<div style='width:600px; height:32px;padding:19px 0; line-height:32px; background:#212121; color:#959595;'>" +
"<a href='tencent://message/?uin=21734770&Site==一起邮币卡&Menu=yes' style='margin:10px;'>" +
 "           <img style='vertical-align:bottom' src='http://www.17ybk.com/edm/20160513/images/qq.jpg' width='101' height='32' alt='QQ投稿入驻' title='QQ投稿入驻'/></a> " +
"<a href='tencent://message/?uin=21734770&Site==一起邮币卡&Menu=yes'>" +
"            <img src='http://www.17ybk.com/edm/20160513/images/qq_2.jpg' width='101' height='32' alt='QQ合作咨询' title='QQ合作咨询' style='vertical-align:bottom;margin-right:10px;'/></a> " +
" <img src='http://www.17ybk.com/edm/20160513/images/tel.jpg' width='26' height='26' alt='' style='vertical-align:bottom;margin-right:5px;position:relative;bottom:3px'/>400-777-3126" +
"     <img src='http://www.17ybk.com/edm/20160513/images/mail.jpg' width='26' height='26' alt='' style='vertical-align:bottom;margin-right:5px;margin-left:5px;position:relative;bottom:3px'/>" +
 "           service@17ybk.com</div>" +
"<a href='http://www.17ybk.com/edm/20160513/index.htm' target='_blank'> 点击查看网页版http://www.17ybk.com/edm/20160513/index.htm</a>" +
"</body>" +
"</html>";
            return html;
            
        }
    }
}
